//
//  HttpBaseModel.m
//  RuiBenO2O
//
//  Created by LiYinDi on 14-10-14.
//  Copyright (c) 2014年 RuiBen. All rights reserved.
// 

#import "HttpBaseModel.h"
#import "AFNetworking.h"
@implementation HttpBaseModel
+(void)severRequest:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
//    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
   
  NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
  NSString* MainURLs = [user objectForKey:@"AppUrls"];
    
    
//MainURLs=@"http://www.try-shopping.com:5080/HDShoppingGuide";
    
//    if (MainURLs ==nil) {
//        MainURLs=@"http://www.try-shopping.com:5080/HDShoppingGuide";
//    }
 
//    
     NSString *url=[NSString stringWithFormat:@"%@/app/%@",MainURLs,path];//选择api
   // NSLog(@"http######===%@",url);
        [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
          //  NSLog(@"http######===%@",operation.responseString);
        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        completionBlock(responseDict);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        errorBlock(error.localizedDescription);
         NSLog(@"failure operation==%@",error);
    }];
}

+(void)severRequest1:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
{
    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
    // 设置请求格式
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    // 设置返回格式
    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
//    NSString *url=[NSString stringWithFormat:@"%@%@",@"http://reabam.f3322.org:90/zbDemo/api/",path];//选择api
    NSString *url=[NSString stringWithFormat:@"%@%@",waiMainURL,path];
    
    [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //  NSLog(@"http######===%@",operation.responseString);
        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
        completionBlock(responseDict);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        errorBlock(error.localizedDescription);
        NSLog(@"failure operation==%@",error);
    }];
}



//+(void)severRequest2:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
//{
//    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
//    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
//    // 设置请求格式
//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    // 设置返回格式
//    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    
//    
//    NSString *url=[NSString stringWithFormat:@"%@%@",MainURL2,path];
//    
//    [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        //  NSLog(@"http######===%@",operation.responseString);
//        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
//        completionBlock(responseDict);
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        errorBlock(error.localizedDescription);
//        NSLog(@"failure operation==%@",error);
//    }];
//}
//+(void)severRequest3:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
//{
//    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
//    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
//    // 设置请求格式
//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    // 设置返回格式
//    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    
//    
//    NSString *url=[NSString stringWithFormat:@"%@%@",MainURL222,path];//固定登录借用导购的api
//    
//    [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        //  NSLog(@"http######===%@",operation.responseString);
//        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
//        completionBlock(responseDict);
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        errorBlock(error.localizedDescription);
//        NSLog(@"failure operation==%@",error);
//    }];
//}
//+(void)severRequest4:(NSString *)path params:(NSMutableDictionary *)params onCompletion:(void(^)(NSDictionary *responseData))completionBlock onError:(void(^)(NSString *error))errorBlock
//{
//    AFHTTPRequestOperationManager *manager=[AFHTTPRequestOperationManager manager];
//    manager.responseSerializer.acceptableContentTypes=[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html", nil];
//    manager.responseSerializer=[AFHTTPResponseSerializer serializer];
//    // 设置请求格式
//    manager.requestSerializer = [AFJSONRequestSerializer serializer];
//    // 设置返回格式
//    //    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
//    
//    
//    NSString *url=[NSString stringWithFormat:@"%@%@",@"",path];//借用导购的api
//    
//    [manager POST:url parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        //  NSLog(@"http######===%@",operation.responseString);
//        NSDictionary *responseDict=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
//        completionBlock(responseDict);
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        errorBlock(error.localizedDescription);
//        NSLog(@"failure operation==%@",error);
//    }];
//}
//

@end
